perm filename OFORK.JP[LIB,LSP] blob sn#290543 filedate 1977-06-27 generic text, type C, neo UTF8
COMMENT āŠ—   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	A preliminary version of a fork package for MACLSP is available in a relatively
C00010 ENDMK
CāŠ—;
A preliminary version of a fork package for MACLSP is available in a relatively
undebugged state. For those of you who risk to use it, here is a short description
of how to do so.

FORK.FAS[LIB,LSP]
This fasload file provides a number of functions for the dynamic creation of
MACLSP forks and arbitrary synchronization and intercommunication between  them.
The basis for the fork facility is a message system. MACLSP processes running
in separate jobs intercommunicate via these messages. There is currently a simple
message and synchronization facility, as well as some higher level primitives
that permit the communication of arbitrary LISP objects between MACLSPs.

Forks are identified by their job number, that is by the job# the SAIL operating
system assigns to the process. The format of messages (from the MACLSP viewpoint)
is a 3-list as follows:
	(messagetype job# . message-txt)
where
	messagetype: non-numeric atom indicating message type, of < 5 chars pname
		     otherwise only the first 5 chars are used.
	job#: fixnum indicating job# of sender
	message: list of < 30 non-numeric atoms, as above, or NIL.
Notice that message-txt is cddr of message. For example a message from job 34 decimal,
of type GARBAGE and with message (FOO COLLECT GARBAGE FOR ME), would be represented
as
	(GARBA 42 FOO COLLE GARBA FOR ME)
within MACLSP. Arbitrary messages can be sent via the file facility described below.

Message system functions available to lusers
--------------------------------------------

sndmsg [mess]	LEXPR
Expects no less than 3 and no more than 4 args. Arg-1 is a fixnum denoting the job#
of some (supposedly) active MACLSP fork in the system. Arg-2 is a message type as
defined above. Arg-3 is the sender's job# as a fixnum. Arg-4 either doesn't
appear or is a list of message atoms as above (< 30 in length). Lists longer than
this will be chopped to length 30.
Returns 
      -	NIL if the message could not be sent because the target process is busy
	looking at its mail.
      -	NOJOB if the there is no such process
      -	T if everything goes fine

waitmsg [msg-type fork#]  SUBR
Waits for a message from fork fork# of type msg-type. If either of these two is NIL,
it acts as a wildcard (i.e any fork, or any type). All messages received before
the right one comes are flushed. Returns only when a message of the right type
and sender arrives. Returns message as value.

chkmsg [msg-type fork#]	 SUBR
Similar to waitmsg but does not wait. If the message doesnt satisfy the constraints
it returns NIL otherwise the message.

getmyjob []   SUBR
Returns job# of process as fixnum.

File intercommunication facility
--------------------------------

createfork[dumpfile downfile] SUBR
Creates a fork, running dumpfile, and starts it up as a phantom. This fork will
dissappear if it hits any kind of error condition or if it (quit)s from MACLSP.
At present both args MUST appear and cannot be NIL. Moreover they MUST be in the
following format
	dumpfile : (filname ext p pn)
	downfile : (filname ext)
The first one is the MACLSP dmp file to run. The second one is a file that is
used for communicating arbitrary messages with the lower fork. This file will
be created in the (CRUNIT) directory and device, only when the file facility
is used (future versions will allow to not specify a file if not necessary).
Returns
	a dotted pair of the form
	    (lowerfork# . upperfile)
	where
	  lowerfork#  : is the job# for the newly created fork
	  upperfile   : file name in same format as downfile that the lower fork
			will use to communicate with the upper fork. Notice that
			it may be the same as downfile, but the systems writer will
			have to synchronize accesses to the file on his/her own.

startfork[upperfile]  SUBR
This function must be executed by the lower fork to establish a handshaking sequence
with the upper fork and exchange communication file names and job numbers. It must
be the first function to be executed when the fork is started (restriction to be
removed)
Returns 
	a dotted pair of the form
	   (upperfork# . downfile)

readfork [commfilename fork#]  SUBR
Waits till fork fork# has written an s-expr (only one s-expr can be written per
writefork, see below) in file commfilename. Once it has done so, reads the 
s-expr and returns it as its value.

writefork[commfilename fork# s-expr]  SUBR
Writes s-expr in file commfilename, notifies fork fork#. Returns result of the
notification (T, NIL or NOJOB as in SNDMSG)

NOTE: There might still be bugs in these routines. CAVEAT EMPTOR! Please report
any bugs or comments → JP